package com.springboot.ykz.dependinject;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.NoSuchMessageException;
import org.springframework.context.annotation.Primary;
import org.springframework.core.ResolvableType;
import org.springframework.core.env.Environment;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.lang.annotation.Annotation;
import java.util.Locale;
import java.util.Map;

@Component
//当animal中有多个实现子类的时候，可以使用primary来指定优先级。如果有两个primary则会报错：，Animal' available: more than one 'primary' bean found among candidates: [cat, dog]
//@Primary
public class Dog implements Animal, BeanNameAware, BeanFactoryAware, ApplicationContextAware,InitializingBean,DisposableBean {
    public void use() {
        System.out.println("Dog hold the door ：【" + getClass().getName() + "】");
    }

    @PostConstruct
    public void myInit() {
        System.out.println("postConstruct 初始化方法"+this.getClass().getSimpleName());
    }
    @PreDestroy
    public void myDestory(){
        System.out.println("postConstruct 自定义销毁方法"+this.getClass().getSimpleName());
    }
    //DisposableBean
    @Override
    public void destroy() throws Exception {
        System.out.println(" 自定义DisposableBean 的destory方法"+this.getClass().getSimpleName());
    }



    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {

    }

    @Override
    public void setBeanName(String s) {

    }


    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("InitializingBean的 afterPropertiesSet方法"+this.getClass().getSimpleName());
    }

    //
    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {

    }
}
